package org.company.management;

import java.awt.Dimension;
import java.awt.Toolkit;

import org.company.management.utilities.Strings;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
import org.eclipse.ui.application.WorkbenchWindowAdvisor;

/**
 * @author Paner
 *
 */
public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {

	private static int _windowWidth = Strings.windowWidth;
	private static int _windowHeight = Strings.windowHeight;
	
    public ApplicationWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
        super(configurer);
    }

    public ActionBarAdvisor createActionBarAdvisor(IActionBarConfigurer configurer) {
        return new ApplicationActionBarAdvisor(configurer);
    }
    
    public void preWindowOpen() {
        IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
        configurer.setInitialSize(new Point(_windowWidth, _windowHeight));
        configurer.setShowCoolBar(true);
        configurer.setShowStatusLine(true);
        configurer.setShowPerspectiveBar(false);
        configurer.setShowMenuBar(true);    
        
        configurer.setTitle(Strings.applicationName);
    }
    
    @Override
    public void postWindowCreate() {
    	
    	//calculate  dimensions, to open window in the center of the screen
    	Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    	int x = (dim.width-_windowWidth)/2;
    	int y = (dim.height-_windowHeight)/2;
    	
    	Shell shell = getWindowConfigurer().getWindow().getShell();
    	shell.setLocation(x, y);
    	super.postWindowCreate();
    }

}
